const { DataTypes, Model, Op } = require('../../../azeroth').sequelize;
class PanelInfo extends Model { }
const { linedb_cf_jingdujiance_config } = require('../../config.json').line_db; // 源库
const seq = require('../../lib/db').getSequelizeInstance(linedb_cf_jingdujiance_config);
PanelInfo.init(
    {
        uid: {
            field: 'uid',
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        job_id: {
            field: 'job_id',
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: false
        },
        panel_id: {
            field: 'panel_id',
            type: DataTypes.STRING
        },
        flaw_count: {
            field: 'flaw_count',
            type: DataTypes.INTEGER
        },
        is_ok: {
            field: 'is_ok',
            type: DataTypes.INTEGER
        },
        length_md: {
            field: 'length_md',
            type: DataTypes.INTEGER
        },
        length_cd: {
            field: 'length_cd',
            type: DataTypes.INTEGER
        },
        save_path: {
            field: 'save_path',
            type: DataTypes.STRING
        },
        gen_time: {
            field: 'gen_time',
            type: DataTypes.BIGINT
        },
        gen_time_str: {
            field: 'gen_time_str',
            type: DataTypes.STRING
        },
        detectParam: {
            field: 'detectParam',
            type: DataTypes.TEXT
        },
        checked: {
            field: 'checked',
            type: DataTypes.INTEGER
        },
    },
    {
        freezeTableName: true,
        sequelize: seq,
        modelName: 'panel',
        timestamps: false
    }
)

PanelInfo.getMaxUid = async () => {
    let res = seq.query(`select max(uid) as uid from panel`, { type: seq.QueryTypes.SELECT });
    if (res.length) {
        return res[0].uid;
    } else {
        return 0;
    }
}

PanelInfo.upload = async (data) => {
    let res = await PanelInfo.bulkCreate([data], { updateOnDuplicate: ['uid'] });
    return res;
}

module.exports = PanelInfo;